#include <cmath>
#include <iostream>
using namespace std;
 
bool isPrime(long long x) // 参数也要开long long 
{
	if (x < 2)
		return false;
	for (int i = 2; i <= sqrt(x); ++i)
	{
		if (x % i == 0)
			return false;
	}
	return true;
}
 
int main()
{
	int t = 0;
	cin >> t;
	while (t--)
	{
		long long a = 0, b = 0;
		cin >> a >> b;
		if ((a == 1 && isPrime(b)) || (b == 1 && isPrime(a)))
			cout << "YES" << endl;
		else
			cout << "NO" << endl;
	}
	return 0;
}